﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace JSG.BubbleShoot.ScriptableObjects
{
    [CreateAssetMenu(fileName = "DataStorage", menuName = "CustomObjects/DataStorage", order = 1)]
    public class DataStorage : ScriptableObject
    {
        [HideInInspector]


        [Space]
        public bool m_DisableUpgrades;


        [HideInInspector]
        public int PlayerScore = 0;


        //-----------------------------ads and rewards
        [HideInInspector]
        public int GameAdsCounter = 0;
        [HideInInspector]
        public int GameAdsDelay = 0;

        [Space]
        public int LevelCoin;
        public int Coin;
        public int Level;
        public int LevelUnlocked;

        public int[] m_PowerCounts;


        public int[] m_LevelPowerReward;



        [Space]
        public Content m_Contents;

        public void SaveData()
        {


            PlayerPrefs.SetInt("Level", Level);
            PlayerPrefs.SetInt("LevelUnlocked", LevelUnlocked);



            PlayerPrefs.SetInt("Coin", Coin);


            if (m_DisableUpgrades)
                PlayerPrefs.SetInt("m_DisableUpgrades", 1);
            else
                PlayerPrefs.SetInt("m_DisableUpgrades", 0);




            for (int i = 0; i < 3; i++)
            {
                PlayerPrefs.SetInt("m_PowerCounts" + i.ToString(), m_PowerCounts[i]);
            }






        }

        public void LoadData()
        {

            Level = PlayerPrefs.GetInt("Level", 0);
            LevelUnlocked = PlayerPrefs.GetInt("LevelUnlocked", 0);
            Coin = PlayerPrefs.GetInt("Coin", 0);



            m_PowerCounts = new int[3];
            for (int i = 0; i < 3; i++)
            {
                m_PowerCounts[i] = PlayerPrefs.GetInt("m_PowerCounts" + i.ToString(), 0);
            }

            m_DisableUpgrades = (PlayerPrefs.GetInt("m_DisableUpgrades", 0) == 1);
        }

        public void ResetDate()
        {
            Coin = 0;
            SaveData();
        }



        public bool CheckInternet()
        {
            if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork || Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
                return true;
            return false;
        }
    }
}
